from appium import webdriver
from selenium.webdriver.common.by import By

from xueqiu_app_po.base.BasePage import BasePage



class XueQiuApp(BasePage):

    def start(self):
        # 定义一个json串
        caps = {}
        # 设置app的平台 Android或者 ios
        caps["platformName"] = "android"
        # 设备的名字
        caps["appium:deviceName"] = "xueqiu"
        # 设备的包名
        caps["appium:appPackage"] = "com.xueqiu.android"
        # 设备app的启动页
        caps["appium:appActivity"] = ".view.WelcomeActivityAlias"
        # 不清空缓存启动app
        caps["appium:noReset"] = "true"
        # 不重启app
        caps["appium:dontStopAppOnReset"] = "true"
        # 设置版本
        caps["platformVersion"] = '6.0'
        self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", caps)
        # 设置全局隐式等待
        self.driver.implicitly_wait(10)
        return self
    def restart(self):
        # 重启app
        # 关闭app
        self.driver.close()
        # 激活后台的app
        self.driver.activate_app("com.tencent.wework")
        return self
    def stop(self):
        self.driver.quit()
    def goto_main_page(self):
        from xueqiu_app_po.page.main_page import MainPage
        return MainPage(self.driver)
    def click_main(self):
        self.find_and_click(By.XPATH,"//*[@text = '雪球']")